# 导入依赖包
import oracledb

# 指定Oracle客户端安装路径  其实就是找 oci.dll  动态库
oracledb.init_oracle_client(lib_dir=r"c:\instantclient-basic-windows.x64-23.8.0.25.04\instantclient_23_8")

# 建立连接
connection = oracledb.connect(
    user="scott",
    password="123456",
    dsn="localhost:1521/orcl"
)


# 创建游标
cursor = connection.cursor()
# 执行查询
cursor.execute("SELECT * FROM emp")

# 获取结果
for row in cursor:
    print(row)

# 关闭游标和连接
cursor.close()
connection.close()